package com.itheima.controller;

import com.itheima.pojo.User;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/test01")
    public ModelAndView test01(ModelAndView modelAndView, Integer id, String username) {

        modelAndView.addObject("nowDate", new Date());
        modelAndView.addObject("msg", "id:" + id + ",username:" + username);

        modelAndView.setViewName("message");
        return modelAndView;
    }

    @RequestMapping("/test02")
    public ModelAndView test02(Integer id, String username) {

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("nowDate", new Date());
        modelAndView.addObject("msg", "id:" + id + ",username:" + username);

        modelAndView.setViewName("message");
        return modelAndView;
    }

    @RequestMapping("/test03")
    //自定义类型转换器
    public ModelAndView test03(Date date) {

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("message");
        modelAndView.addObject("nowDate", new Date());
        modelAndView.addObject("msg", date);

        return modelAndView;
    }

    @RequestMapping("/test04")
    //日期格式转换 注解方式
    public ModelAndView test04(@DateTimeFormat(pattern = "yyyy-MM-dd") Date date) {

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("message");
        modelAndView.addObject("nowDate", new Date());
        modelAndView.addObject("msg", date);

        return modelAndView;
    }
}
